package com.youlu.campus.web.certificate.controller;

import com.youlu.campus.web.certificate.CertificateService;
import com.youlu.campus.web.certificate.dto.YLCertificateFinalImageSyncRequest;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 证书控制层
 * 处理证书相关的同步、查询及领取等操作
 *
 * @author: zhuhuaiqi
 * @date: 2020/11/27 15:19
 */
@Slf4j
@RestController
public class CertificateController {

    @Autowired
    private CertificateService certificateService;

    /**
     * 证书生成图片同步
     * 用于优路证书生成图片的同步操作
     * @param request 证书图片同步请求参数
     * @return 同步结果
     */
    @PostMapping("/public/temp/certificate/final/image/sync")
    public QResult syncCertificateFinalImage(@RequestBody @Valid YLCertificateFinalImageSyncRequest request) {
        return QResult.success(certificateService.syncCertificateFinalImage(request));
    }

    /**
     * 获取证书列表
     * 查询当前用户的证书列表信息
     * @return 证书列表数据
     */
    @GetMapping("/mini-app/certificate/list")
    public QResult getCertificateInfo() {
        return QResult.success(certificateService.getCertificateInfo());
    }

    /**
     * 证书领取
     * 根据证书ID领取对应的证书
     * @param id 证书ID
     * @return 领取结果
     */
    @GetMapping("/mini-app/certificate/receive")
    public QResult receiveCertificate(String id) {
        return QResult.success(certificateService.receiveCertificate(id));
    }
}